
import { _decorator, Component, Node, CCBoolean, AudioClip } from 'cc';
import { FileName } from '../ConstView/ConstType'

const { ccclass, property } = _decorator;


/**
 * Predefined variables
 * Name = PlayManager
 * DateTime = Wed Sep 07 2022 10:53:54 GMT+0800 (中国标准时间)
 * Author = 3303538033
 * FileBasename = PlayManager.ts
 * FileBasenameNoExtension = PlayManager
 * URL = db://assets/PlayManager.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */

@ccclass('PlayManager')
export class PlayManager extends Component {


    @property(CCBoolean)
    isPlay: Boolean

    @property(Node)
    AudioNode: Node


    Up_p: Node;
    Center_p: Node;
    Down_p: Node;
    AudioNodesJs: any;

    tt: number;


    onLoad() {
        this.tt = 0
        this.AudioNodesJs = this.AudioNode.getComponent('AudioManager')
        this.Up_p = this.node.getChildByName('Up_p')
        this.Center_p = this.node.getChildByName('Center_p')
        this.Down_p = this.node.getChildByName('Down_p')
    }

    start() {
        //监听事件
        //----前一首----/
        this.Up_p.on(Node.EventType.TOUCH_START, this.UP_Clicks, this)
        this.Up_p.on(Node.EventType.TOUCH_END, this.UP_Click, this)

        //-----暂停----/
        this.Center_p.on(Node.EventType.TOUCH_END, this.Center_Click, this)

        //-----后一首----/
        this.Down_p.on(Node.EventType.TOUCH_START, this.Down_Clicks, this)
        this.Down_p.on(Node.EventType.TOUCH_END, this.Down_Click, this)
        // [3]
    }

    UP_Click() {
        this.tt = this.tt + (this.tt == 0 ? (FileName.length - 1) : -1)

        this.AudioNodesJs.playi(FileName[this.tt])
        this.isPlay = true
    }

    UP_Clicks() {
        this.AudioNodesJs.playEffet('getMoney', 0.2)
        this.AudioNodesJs.pausei()
    }

    Center_Click() {
        this.isPlay = !this.isPlay
        if (this.isPlay) {
            this.AudioNodesJs.continueplay()
        }
        if (!this.isPlay) {
            this.AudioNodesJs.pausei()
        }
    }

    Down_Clicks() {
        this.AudioNodesJs.playEffet('getMoney', 0.2)
        this.AudioNodesJs.stopi()

    }

    Down_Click() {
        this.tt = this.tt + (this.tt == FileName.length - 1 ? -(FileName.length - 1) : 1)

        this.AudioNodesJs.playi(FileName[this.tt])
        this.isPlay = true
    }

    // update (deltaTime: number) {
    //     // [4]
    // }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/decorator.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
 */
